package net.wlm.realtime.funcation;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.flink.api.common.functions.RichMapFunction;
import org.apache.flink.configuration.Configuration;

import java.util.HashMap;

/*
 * 对维度表CDC数据，增加写入HBASE表数据对应字段信息：表名称、列簇名称、RowKey值对应字段名称等
 */

public class HbaseDimMapFunction extends RichMapFunction<String,String> {
    private HashMap<String,String> dimMap;
    public HbaseDimMapFunction(HashMap<String, String> dimMap) {
        this.dimMap = dimMap;
    }

    @Override
    public void open(Configuration parameters) throws Exception {
        super.open(parameters);
    }

    @Override
    public String map(String s) throws Exception {
        // 解析JSON
        JSONObject jsonObject = JSON.parseObject(s);
        // 添加字段--hbase表名称
        jsonObject.put("hbase_table_name","dim_"+jsonObject.getString("table_name"));
        // 添加字段--列簇名称
        jsonObject.put("family_name","info");
        // 添加字段--rowKey值对应字段名称
        jsonObject.put("row_key_column",dimMap.get(jsonObject.getString("table_name")));
        // 返回
        return jsonObject.toJSONString();
    }

    @Override
    public void close() throws Exception {
        super.close();
    }

}
